package com.zzz.gp.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;

/**
 * @description:
 * @author: ZZZ
 * @time: 2023/8/2 17:20
 */
@Component
public class TackDynamic {
    @Autowired
    public ThreadPoolTaskScheduler threadPoolTaskScheduler;
    @Autowired
    public Task1 task1;
    @Autowired
    public Task2 task2;

    /**
     * 存放已经启动的任务map
     */
    private ConcurrentHashMap<String, ScheduledFuture> scheduledFutureMap = new ConcurrentHashMap<>();


    //@PostConstruct
    public void init(){
        ScheduledFuture<?> task1Schedule = threadPoolTaskScheduler.schedule(task1, new CronTrigger("0/5 *  1 * * ?"));
        scheduledFutureMap.put("task1",task1Schedule);
        ScheduledFuture<?> task2Schedule = threadPoolTaskScheduler.schedule(task2, new CronTrigger("0/2 *  1 * * ?"));
        scheduledFutureMap.put("task2",task2Schedule);


    }
}
